package Connect;

use strict;
use warnings;

use DBI;
use IO::Socket;

sub db_con
{
    my ($db,$user,$pw)=@_;
    my $dbh = DBI->connect("DBI:mysql:database=$db;host=localhost","$user","$pw",{'RaiseError' => 0});
	#or die "\[ERROR] Can't connect to the database.\n[Error] $DBI::errstr\n";

    return ($dbh);
}


sub db_discon
{
    my $dbh = shift @_;
    
    my $result=$dbh->disconnect();
    
    if ($result eq "0")
    {
	return "no";
    }
    else
    {
	return "yes";
    }
}

sub slsecd_connect
{
    my $socket=shift @_;
    my $proto=shift @_;
    my $peeraddr=shift @_;
    my $peerport=shift @_;
    
    $$socket=IO::Socket::INET->new( Proto     => $$proto,
				      PeerAddr  => $$peeraddr,
				      PeerPort  => $$peerport
				      );
    unless ($$socket)
    {
	return 0;
    }
    return 1;
}

sub slsecd_disconnect
{
    my $socket=shift @_;
    
    close $$socket;
}

1;
